package core.dao;

import core.entity.Category;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by Christian Waickem on 9/22/2014.
 */
@Repository
public class CategoryDAO {

    @PersistenceContext
    EntityManager em;

    public void createTopic(Category category) {
        em.merge(category);
    }

    public List<Category> getAllCategories(){
        return em.createQuery("SELECT t from Category t", Category.class)
                .getResultList();
    }

    public void deleteCategory(Category category){
        em.remove(category);
    }

    public void updateCategory(Category category){
        em.merge(category);
    }

    public Category findCategory(long id) {
        return em.find(Category.class, id);
    }
}
